﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd2010r
/// 파  일  명 : Crd2010r.aspx.cs
/// 설      명 : 카드명세서
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-07-23 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Adapter;
using SMFramework.Data;
using SMFramework.Security;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Crd.Exe;
using Updms.Common.BaseClass;


namespace Updms.Crd
{
	public partial class Crd2010r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Crd2010r";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();
		Crypto crypto = new Crypto();
		CommCode.Crd crd = new CommCode.Crd(LANG_SET);

		//검색
		protected string kw1 = "";	// card_cd
		protected string kw2 = "";	// paymnt_dt
		protected string kw3 = "";	// 제외할 시스템ID : CRD
		protected string kw4 = "";	// 구분 prefix : C
		protected string kw5 = "";	// 정렬

		//메뉴 선택값
		protected string gs_sm = "";

		//페이지모드
		private string gs_page_mode = "";	// 팝업으로 열지 여부

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SearchProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetCardInfo();
			SetPaymntDtList(ddl_search_card_cd.SelectedValue);
			SetInquiryDiv();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion		

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";			

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();

			gs_page_mode = (Request.QueryString["page_mode"] == null || Request.QueryString["page_mode"].Trim().Length == 0)
					? "" : Request.QueryString["page_mode"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
					{
						kw1 = ddl_search_card_cd.SelectedValue;
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						ddl_search_card_cd.SelectedValue = kw1;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw2"])) // url에 값이 없으면
					{
						kw2 = ddl_search_paymnt_dt.SelectedValue;
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						ddl_search_paymnt_dt.SelectedValue = kw2;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw5"])) // url에 값이 없으면
					{
						kw5 = ddl_search_order_by.SelectedValue;
					}
					else
					{
						kw5 = Server.UrlDecode(Request.QueryString["kw5"]);
						ddl_search_order_by.SelectedValue = kw5;
					}
					break;
				case "SEARCH":
					kw1 = ddl_search_card_cd.SelectedValue;
					kw2 = ddl_search_paymnt_dt.SelectedValue;
					kw5 = ddl_search_order_by.SelectedValue;
					break;
			}

			kw3 = cb_support_yn.Checked ? "CRD" : "";
			kw4 = cb_support_yn.Checked ? "AG" : "";
		}

		#endregion

		#region 마스터 Method (SetCardInfo, SetPaymntDtList, SelectPaymntDt, SetInquiryDiv, SetConfirmEnabled)

		// 카드정보에서 카드정보를 가져와서 ddl_search_card_cd에 채운다.
		private void SetCardInfo()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			ddl_search_card_cd.Items.Clear();
			ddl_search_card_cd.DataSource = lo_ds;
			ddl_search_card_cd.DataMember = "UPDMS_CRD_INFO";
			ddl_search_card_cd.DataTextField = "Card_Nm";
			ddl_search_card_cd.DataValueField = "Card_Cd";
			ddl_search_card_cd.DataBind();

			//카드사용그래프에서 넘어온 경우
			if (!String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 있으면
			{
				ddl_search_card_cd.SelectedValue = Server.UrlDecode(Request.QueryString["kw1"]);
			}
		}

		// 카드코드별 결제예정일리스트를 가져와서 ddl_paymnt_dt에 바인딩한다.
		private void SetPaymntDtList(string ls_card_cd)
		{
			DataSet lo_ds = new DataSet();
			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_ds.Merge(_Crd1011m_NT.GetPaymntDtList(ls_card_cd));

			ddl_search_paymnt_dt.Items.Clear();
			ddl_search_paymnt_dt.DataSource = lo_ds;
			ddl_search_paymnt_dt.DataMember = "UPDMS_CRD_PAYMNT_DT";
			ddl_search_paymnt_dt.DataTextField = "Text";
			ddl_search_paymnt_dt.DataValueField = "Value";
			ddl_search_paymnt_dt.DataBind();
			SelectPaymntDt();
		}

		//오늘을 기준으로 결제일자 선택(카드사용그래프에서 넘어온 경우 반영)	
		private void SelectPaymntDt()
		{
			int li_today = Convert.ToInt32(DateUtil.GetMonthEx(0, "yyyyMMdd")); // 20070131
			int ddl_cnt = ddl_search_paymnt_dt.Items.Count;
			bool lb_no_paymnt_dt = true;

			for (int i = 0; i < ddl_cnt; i++)
			{
				if (li_today < ConversionUtil.ExtractNumberInt(ddl_search_paymnt_dt.Items[i].Text))
				{
					ddl_search_paymnt_dt.SelectedIndex = i;
					i = ddl_cnt;
					lb_no_paymnt_dt = false;
				}
			}

			//없으면 가장 최근의 결제일자로 셋팅
			if (lb_no_paymnt_dt)
			{
				ddl_search_paymnt_dt.SelectedIndex = ddl_cnt - 1;
			}
		}

		//조회구분
		private void SetInquiryDiv()
		{
			crd.SetInquiryDiv(ddl_search_order_by);
		}

		//확정버튼 Enabled처리
		private void SetConfirmEnabled()
		{
			using (Crd2010r_NT _Crd2010r_NT = new Crd2010r_NT())
			{
				ibtn_confirm.Enabled 
				= _Crd2010r_NT.IsConfirmYn(ddl_search_card_cd.SelectedValue, ddl_search_paymnt_dt.SelectedValue);
			}

			if (ibtn_confirm.Enabled)
			{
				// 확정버튼에 attribute부여
				string ls_card_nm = ddl_search_card_cd.SelectedItem.Text;
				string ls_paymnt_dt = ddl_search_paymnt_dt.SelectedItem.Text;

				ibtn_confirm.Attributes.Add("title", GetXmlMsg("STR_004"));//확정할 수 있습니다
				ibtn_confirm.Attributes.Add("onclick", "return chkConfirm('" + ls_card_nm + "', '" + ls_paymnt_dt + "')");
				ibtn_confirm.Attributes.Add("class", "ibtn ibtn_confirm");
			}
			else
			{
				ibtn_confirm.Attributes.Add("title", GetXmlMsg("STR_008")); //이미 확정되었습니다
				ibtn_confirm.Attributes.Remove("onclick");
				ibtn_confirm.Attributes.Add("class", "ibtn ibtn_confirmed");
			}
		}

		#endregion

		#region 마스터 Method (SetPrevNextMonth, SetThisMonth, SetEnabledMonthBtn)

		//전월, 차월버튼 누르면
		private void SetPrevNextMonth(int idx)
		{
			int li_curr_idx = ddl_search_paymnt_dt.SelectedIndex;
			ddl_search_paymnt_dt.SelectedIndex = li_curr_idx + idx;

			//버튼처리
			SetEnabledMonthBtn();
		}

		//당월설정
		private void SetThisMonth()
		{
			SelectPaymntDt();
			SetEnabledMonthBtn();
		}

		//전월, 차월버튼 처리
		private void SetEnabledMonthBtn()
		{
			ibtn_prev_month.Enabled = (ddl_search_paymnt_dt.SelectedIndex == 0) ? false : true;
			ibtn_next_month.Enabled = (ddl_search_paymnt_dt.SelectedIndex == ddl_search_paymnt_dt.Items.Count - 1) ? false : true;
		}

		#endregion

		#region 디테일 Method (SetSummaryList, CreateFileReal, TransferFtp)

		//카드요약정보
		private void SetSummaryList()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			string ls_table = "UPDMS_CRD_REPORT";

			//검색
			lo_dp.AddProperty("ls_card_cd", typeof(string), ddl_search_card_cd.SelectedValue);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), ddl_search_paymnt_dt.SelectedValue);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
			
			if (ddl_search_paymnt_dt.Items.Count > 0)
			{
				using (Crd2010r_NT _Crd2010r_NT = new Crd2010r_NT())
				{
					lo_ds.Merge(_Crd2010r_NT.GetCardSummary(lo_dp));

					string ls_mass_st_dt = DataSetUtil.GetFldStr(lo_ds, ls_table, "Mass_St_Dt");
					string ls_mass_ed_dt = DataSetUtil.GetFldStr(lo_ds, ls_table, "Mass_Ed_Dt");
					string ls_cash_st_dt = DataSetUtil.GetFldStr(lo_ds, ls_table, "Cash_St_Dt");
					string ls_cash_ed_dt = DataSetUtil.GetFldStr(lo_ds, ls_table, "Cash_Ed_Dt");
					string ls_bnk_nm = DataSetUtil.GetFldStr(lo_ds, ls_table, "Bnk_Nm");
					string ls_accnt_num = DataSetUtil.GetFldStr(lo_ds, ls_table, "Accnt_Num");
					string ls_card_image = DataSetUtil.GetFldStr(lo_ds, ls_table, "Attach_File1");
					string ls_limit_use = DataSetUtil.GetFldStr(lo_ds, ls_table, "Limit_Use");
					string ls_limit_cash = DataSetUtil.GetFldStr(lo_ds, ls_table, "Limit_Cash");

					lbl_mass_ins.Text = "<a href=\"javascript:void(0);\" onclick=\"goCardMassPage('" + global.GetDirDepth("Crd1012m") + "','" + kw1 + "','','" + ls_mass_st_dt + "','" + ls_mass_ed_dt + "','','T');\"><u>" + GetXmlMsg("STR_010") + "</u></a>";

					lbl_mass_dt.Text = ls_mass_st_dt + " ~ " + ls_mass_ed_dt;
					lbl_cash_dt.Text = ls_cash_st_dt + " ~ " + ls_cash_ed_dt;
					lbl_bnk_nm.Text = ls_bnk_nm;
					lbl_accnt_num.Text = ls_accnt_num;
					img_card_image.Src = FILE_PATH_UPLOAD_WEB_PATH + (string.IsNullOrEmpty(ls_card_image) ? "empty.png" : ls_card_image);
					lbl_limit_use.Text = ls_limit_use;
					lbl_limit_cash.Text = ls_limit_cash;
				}
			}
			else
			{
				CallMsgBoxInAjax("MSG_ERR_142");	//지정된 결제일이 없습니다.\n'카드결제일관리'에서 추가해 주세요
			}		
		}

		//실제파일생성
		private void CreateFileReal(string ls_file_nm, DataSet ds, string title)
		{
			string tableName = "UPDMS_CRD_REPORT";
			string ls_stream = FILE_PATH_FTP_UPLOAD + "\\" + ls_file_nm;
			string subTitle = "<div class=\"sub_title\">";
			string paymntDt = DataSetUtil.GetFldStr(ds, tableName, 0, "Paymnt_Dt");

			try
			{
				FileInfo file = new FileInfo(ls_stream);
				StreamWriter sw = file.CreateText();

				//서브타이틀 생성
				for (int i = 0; i < ddl_search_card_cd.Items.Count; i++)
				{
					string cardCd = ddl_search_card_cd.Items[i].Value;
					string cardNm = ddl_search_card_cd.Items[i].Text;
					string cls = (title == cardNm) ? "crd" : "crd not_selected";
					string imgLink = PID + "_" + cardCd + ".html";
					string imgSrc = "<img src=\"../image/" + cardCd + ".gif\"" + " class=\"" + cls + "\" alt=\"" + cardNm + "\" />";

					subTitle += "<a href=\"" + imgLink + "\" target=\"main\">" + imgSrc + "</a>";
				}
				subTitle = subTitle + "</div>";

				sw.WriteLine(CommUtil.GetDefaultHtmlTag(PID, global.GetMenuTitle(PID, LANG_SET) + " (" + title + ", " + paymntDt + ")", false));
				sw.WriteLine(subTitle);
				sw.WriteLine("<table id=\"report_table\" class=\"report\">");
				sw.WriteLine("<tr>");
				sw.WriteLine("<th>결제일</th>");
				sw.WriteLine("<th>결제구분</th>");
				sw.WriteLine("<th>계정</th>");
				sw.WriteLine("<th>결제내용</th>");
				sw.WriteLine("<th>상세내용</th>");
				sw.WriteLine("<th>당월금액</th>");
				sw.WriteLine("</tr>");
				for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
				{
					string bizDt = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Dt");
					string bizDiv = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Div");
					string bizDivNm = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Div_Nm");
					string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
					string contents = DataSetUtil.GetFldStr(ds, tableName, i, "Contents");
					string realRemark = DataSetUtil.GetFldStr(ds, tableName, i, "Real_Remark");
					string amount = DataSetUtil.GetFldStr(ds, tableName, i, "Amount");

					//소계, 총계
					if (bizDiv == "BA001" || bizDiv == "BA002" || bizDiv == "BA003")
					{
						sw.WriteLine("<tr class=\"sub_total\">");
					}
					else if (bizDiv == "BB006")
					{
						sw.WriteLine("<tr class=\"total\">");
					}
					else
					{
						sw.WriteLine("<tr>");
					}

					sw.WriteLine("<td class=\"lbl_c\">" + bizDt + "</td>");
					sw.WriteLine("<td class=\"lbl_c\">" + bizDivNm + "</td>");
					sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
					sw.WriteLine("<td class=\"lbl\">" + contents + "</td>");
					sw.WriteLine("<td class=\"lbl\">" + realRemark + "</td>");
					sw.WriteLine("<td class=\"data\">" + amount + "</td>");
				
					sw.WriteLine("</tr>");
				}
				sw.WriteLine("</table>");
				sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
				sw.WriteLine("TableRowspan(report_table, '1');TableRowspan(report_table, '1');");
				sw.WriteLine("</script>");
				sw.WriteLine("</body>");
				sw.WriteLine("</html>");

				sw.Close();
			}
			catch (Exception e)
			{
				Base.AppFramework.SMEventLog.WriteExceptionLog(e);
				CallMsgBoxInAjax("MSG_ERR_122");	//파일을 생성하지 못했습니다
			}
		}

		//FTP전송
		private void TransferFtp(bool isBulkUploadYn)
		{
			FtpClient fc = new FtpClient(FTP_HOSTNAME, FTP_USERID, crypto.Decrypt(FTP_PASSWORD));
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			string cardCds = isBulkUploadYn ? WebControlUtil.GetDdlValueToString(ddl_search_card_cd) : ddl_search_card_cd.SelectedValue;
			string cardNms = isBulkUploadYn ? WebControlUtil.GetDdlTextToString(ddl_search_card_cd) : ddl_search_card_cd.SelectedItem.Text;
			string ls_paymnt_dt = isBulkUploadYn ? "" : ddl_search_paymnt_dt.SelectedValue;

			try
			{
				SetSearchParameter();

				lo_dp.AddProperty("ls_card_cd", typeof(string));
				lo_dp.AddProperty("ls_paymnt_dt", typeof(string), ls_paymnt_dt);
				lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw3);
				lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw4);
				lo_dp.AddProperty("ls_order_by", typeof(string), kw5);
				lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

				//FTP로그인
				fc.Login();
				fc.BinaryMode = false;

				//디렉토리 이동
				string[] remoteDir = StringUtil.DelimitedListToStringArray(FTP_DIR_IPHONE_CRD, "/");
				for (int i = 0; i < remoteDir.Length; i++)
				{
					fc.ChangeDir(remoteDir[i]);
				}

				string[] la_card_cd = cardCds.Split('^');
				string[] la_card_nm = cardNms.Split('^');

				if (la_card_cd.Length > 0)
				{
					for (int i = 0; i < la_card_cd.Length; i++)
					{
						string cardCd = la_card_cd[i];
						string fileName = PID + "_" + cardCd + ".html";	//Crd2010r_CC09X.html
						
						lo_dp["ls_card_cd"] = cardCd;

						using (Crd2010r_NT _Crd2010r_NT = new Crd2010r_NT())
						{
							lo_ds = _Crd2010r_NT.SelectProcess(lo_dp);
						}

						//파일생성
						CreateFileReal(fileName, lo_ds, la_card_nm[i]);

						//FTP전송
						if (FileUtil.IsFileExist(FILE_PATH_FTP_UPLOAD + "\\" + fileName))
						{
							if (fc.IsFileExist(fileName))
							{
								fc.DeleteFile(fileName);
							}

							fc.UploadOnlyFile(FILE_PATH_FTP_UPLOAD, fileName, "", "", true);
						}
						else
						{
							CallMsgBoxInAjax("MSG_ERR_164");	//전송할 파일이 없습니다.
						}
					}
					CallMsgBoxInAjax("MSG_INF_018");	//전송되었습니다
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
			finally
			{
				fc.Close();
			}
		}


		//카드코드 변경시
		protected void ddl_search_card_cd_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetPaymntDtList(ddl_search_card_cd.SelectedValue);
			
			if (ddl_search_paymnt_dt.Items.Count > 0)
			{
				ibtn_search.Enabled = true;
				ibtn_confirm.Enabled = true;
				ibtn_verify.Enabled = true;
				SearchProcess();
			}
			else
			{
				ibtn_search.Enabled = false;
				ibtn_confirm.Enabled = false;
				ibtn_verify.Enabled = false;
				CallMsgBoxInAjax("MSG_ERR_142");	//지정된 결제일이 없습니다.\n'카드결제일관리'에서 추가해 주세요
			}
		}

		#endregion

		#region CRUD (SelectProcess, ConfirmProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//검색
			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), kw2);
			lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw3);
			lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw4);
			lo_dp.AddProperty("ls_order_by", typeof(string), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd2010r_NT _Crd2010r_NT = new Crd2010r_NT())
			{	
				lo_ds.Merge(_Crd2010r_NT.SelectProcess(lo_dp));
				
				if (!DataSetUtil.CheckRowCount(lo_ds, "UPDMS_CRD_REPORT"))
				{
					CallMsgBoxInAjax("MSG_ERR_111");	// 등록된 내용이 없습니다
				}

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();
			}
		}	

		//확정
		private void ConfirmProcess(string ls_card_cd, string ls_paymnt_dt)
		{
			DataPack lo_dp = new DataPack();
			lo_dp.AddProperty("ls_card_cd", typeof(string), ls_card_cd);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), ls_paymnt_dt);
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);
			
			using (Crd2010r_RT _Crd2010r_RT = new Crd2010r_RT())
			{
				int li_return = _Crd2010r_RT.ConfirmProcess(lo_dp);
				string ls_msg_id = (li_return > 0) ? "MSG_INF_008" : "MSG_ERR_106";	//확정되었습니다:확정할 수 없습니다
				CallMsgBoxInAjax(ls_msg_id);	// 확정되었습니다
			}
			
			//확정후 버튼처리
			SetConfirmEnabled();
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			SetConfirmEnabled();
			SelectProcess();
			SetSummaryList();
		}

		#endregion		

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":		// 처음 페이지로드시
					Top.Visible = true;
					menu_area.Attributes.Add("class", "");
					ibtn_close.Visible = false;
					break;
				case "P":	// 팝업으로 열때
					Top.Visible = false;
					menu_area.Attributes.Add("class", "nodisplay");
					ibtn_close.Visible = true;
					break;
			}
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion		

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;
			
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				string ls_mass_link = "<a href=\"javascript:void(0);\" onclick=\"goCardMassPage('" + global.GetDirDepth("Crd1012m") + "','" + kw1 + "','" + gv.DataKeys[e.Row.RowIndex].Values["Account"].ToString() + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[4].Text + "','T');\">" + e.Row.Cells[4].Text + "</a>";
				string ls_ins_link = "<a href=\"javascript:void(0);\" onclick=\"goCardInsPage('" + global.GetDirDepth("Crd1013m") + "','" + kw1 + "','" + gv.DataKeys[e.Row.RowIndex].Values["Account"].ToString() + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[1].Text + "','T');\">" + e.Row.Cells[4].Text + "</a>";
				
				switch (gv.DataKeys[e.Row.RowIndex].Values["View_Order"].ToString())
				{
					case "10": //일시불
						e.Row.Cells[4].Text = ls_mass_link;
						break;
					case "20": //현금서비스
						e.Row.Cells[4].Text = ls_mass_link;
						break;
					case "30": //할부
						e.Row.Cells[4].Text = ls_ins_link;
						break;						
					case "11": //일시불합계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "21": //현금서비스합계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "31": //할부합계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "91": //총합계
						e.Row.Attributes.Add("class", "total_v3");
						for (int i=0; i< e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_tb_dbl");
						}
						break;
					default:
						//e.Row.Attributes.Add("class", "bg_white");
						break;
				}
			}

			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			sGv.RowSpanGridView(GridView1, 2);

			//사용계정별 정렬이면 계정을 머지한다
			if (ddl_search_order_by.SelectedValue == "Account")
			{
				sGv.RowSpanGridView(GridView1, 3);
			}
		}
		
		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SetEnabledMonthBtn();
			SearchProcess();
		}	

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), kw2);
			lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw3);
			lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw4);
			lo_dp.AddProperty("ls_order_by", typeof(string), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd2010r_NT _Crd2010r_NT = new Crd2010r_NT())
			{
				lo_ds.Merge(_Crd2010r_NT.SelectProcess(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		//확정
		protected void ibtn_confirm_Click(object sender, EventArgs e)
		{
			if (ddl_search_paymnt_dt.Items.Count > 0)
			{
				string ls_card_cd = ddl_search_card_cd.SelectedValue;
				string ls_paymnt_dt = ddl_search_paymnt_dt.SelectedValue;

				ConfirmProcess(ls_card_cd, ls_paymnt_dt);
			}
			else
			{
				CallMsgBoxInAjax("MSG_ERR_106");	// 확정할 수 없습니다
			}
		}

		//FTP
		protected void ibtn_ftp_Click(object sender, EventArgs e)
		{
			TransferFtp(cb_bulk_upload_yn.Checked);
		}

		//전월
		protected void ibtn_prev_month_Click(object sender, EventArgs e)
		{
			SetPrevNextMonth(-1);
			SearchProcess();
		}

		//당월
		protected void ibtn_this_month_Click(object sender, EventArgs e)
		{
			SetThisMonth();
			SearchProcess();
		}

		//차월
		protected void ibtn_next_month_Click(object sender, EventArgs e)
		{
			SetPrevNextMonth(1);
			SearchProcess();
		}

		#endregion		

	}
}
